<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>确认交易</title>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta http-equiv="x-dns-prefetch-control" content="on" />
	<!-- 
	<link rel="dns-prefetch" href="http://static.paipaiimg.com" />
	 -->

	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/alertMsg.js"></script>
    <link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/product/buy_v2.s.min.css?t=1396510799" />    
</head>
<body>
<div id="c_wg.buyOne_show" style>
	<div class="wx_bar">
	    <div class="wx_bar_back">
	    	<a id="indexBack" href="javascript:history.go(-1);"><i></i></a>
	    </div>
	    <div class="wx_bar_tit">确认订单</div>
	</div>
	
	<div class="wx_wrap">
	
		<div class="send_to" id="toAddrList">
		 <notempty name="address">
			<a  onclick="onAddress(this);">
				<div class="address_defalut">
					<h3>送至</h3>
					<ul class="selected" id="editAddBtn" adid=1>
						<li>
							<span id="addr_detail">{$address}</span>
						</li>
						<li>
							<strong><span id="addr_fullName">{$fullName}</span></strong>&nbsp;&nbsp;
							<span id="phone">{$phone}</span>
						</li>
					</ul>
				</div>
			</a>
			<else />
			<a  onclick="onAddress(this);">
				<div class="address_defalut">
					<ul class="selected" id="editAddBtn" adid=1>
						<li>
							<strong>请填写收货地址</strong>
						</li>
					</ul>
				</div>
			</a>
			
			</notempty>
			
		</div>
		
		<div class="send_to" id="toStoreList">
			<a  onclick="onStore(this);">
				<div class="address_defalut">
					<ul class="selected" id="editAddBtn" adid=1>
						<li>
							<strong>自提点名称：</strong>{$lastBuyStoreName}
						</li>
					</ul>
				</div>
			</a>
		</div>
	
		<div class="order_info" id="orderList">
			<h3>订单信息</h3>
			<volist name="productList" id="product">
			<if condition="$i eq 1">
			<dl class="only">
			
				<dd>
					<ul>
						<li class="hproduct">
							<a onclick="onDetail(this,{$product.id})">
							<img class="photo" src="{$product.picUrl}" alt="{$product.name}">
							</a>
							<p class="fn">{$product.name}</p>
							<notempty name="product.colorName">
		    					<p class="sku"> 
									<span>{$product.colorName}</span>
								</p>
		   					</notempty>  
							
							<notempty name="product.sizeName">
			    				<p class="sku"> 
									<span>{$product.sizeName}</span>
								</p>
	    					</notempty>
							
							<notempty name="product.fixedPrice">
					       		<p class="sku"> 
		         					<em>价格：</em>
		         					<notempty name="product.discountedPrice">
										<span>{$product['discountedPrice']}元</span>
		         						<span id="iPrice" price="{$product.discountedPrice}" style="display:none;"></span>
		         					<else />
										<span>{$product['fixedPrice']}元</span>
		         						<span id="iPrice" price="{$product.fixedPrice}" style="display:none;"></span>
								
		         					</notempty>
								</p>
           					</notempty>
           					
          				 	<notempty name="product.points">&nbsp;&nbsp;
		           				<p class="sku"> 
			           				<if condition="$product.pointsType eq 'interact'">
			         					<em>互动积分：</em>
			         				<else />
			         					<em>消费积分：</em>
			         				</if>
									<span>{$product.points}积分</span>
									<span id="iPrice" price="{$product.points}" style="display:none;">{$product.points}积分</span>
								</p>
           					</notempty>
							
							<p class="sku"> 
								<em>数量：</em>
								<span>
									<input pid={$product.id} maxlength="4" tag="comm_count" id="countNum"  maxbuynum="" queryparam="0,0" class="count" type="tel" value="{$product.reserveCount}">
								</span>
								<!-- 
								<span>
									<input maxlength="4" tag="comm_count" id="countNum" inventory="{$product.inventory}" maxbuynum="{$product.inventoryCount}" queryparam="0,0" class="count" type="tel" value="1">
								</span>
								<if condition="($product.inventory eq 1) AND ($product.inventoryCount gt 0)">
								<span class="last" >剩余:<strong>{$product.inventoryCount}</strong></span>
								</if>
								 -->
							</p>
						</li>
						
						<!-- 
						<li class="promo" id="promo" orderid="0">
							<strong>优惠</strong>
							<span >（未使用任何优惠）</span>
						</li>
						 -->
						
						<li class="shipping" orderid="0">
							<strong>配送方式</strong>
							<!-- 
							<span id="noSelectPage" value="{$shipping.value}">（普通快递：免运费）</span>
							 -->
		           		
		           			<select class="addform_select" name="sendTypeId" data-current="" id="sendType">
				           		<if condition="count($shipping) gt 1 && !$deliveryHasDefault">
				            		<option value="-1" cost="-1" mtype="" ptype="0">请选择配送方式</option>
			                	</if>
				           		<volist name="shipping" id="shipping">
				           			<if condition="($shipping.isDefault eq '1')">
					           			<if condition="($shipping.cost eq NULL) AND ($shipping.points eq NULL)">
				                    		<option value="{$shipping.value}" cost="-1" mtype="{$shipping.value}" ptype="0" selected>{$shipping.text}</option>
				                    	<elseif  condition="$shipping.cost neq NULL"/>
				                    		<option value="{$shipping.value}" cost="{$shipping.cost}" mtype="{$shipping.value}" ptype="0" selected>{$shipping.text}： ￥{$shipping.cost}元</option>
				                    	<elseif  condition="$shipping.points neq NULL"/>
				                    		<option value="{$shipping.value}" cost="{$shipping.points}" mtype="{$shipping.value}" ptype="0" selected>{$shipping.text}： {$shipping.points}积分</option>
				                    	</if>
				                    	<else />
				                    	<if condition="($shipping.cost eq NULL) AND ($shipping.points eq NULL)">
				                    		<option value="{$shipping.value}" cost="-1" mtype="{$shipping.value}" ptype="0">{$shipping.text}</option>
				                    	<elseif  condition="$shipping.cost neq NULL"/>
				                    		<option value="{$shipping.value}" cost="{$shipping.cost}" mtype="{$shipping.value}" ptype="0">{$shipping.text}： ￥{$shipping.cost}元</option>
				                    	<elseif  condition="$shipping.points neq NULL"/>
				                    		<option value="{$shipping.value}" cost="{$shipping.points}" mtype="{$shipping.value}" ptype="0">{$shipping.text}： {$shipping.points}积分</option>
				                    	</if>
			                    	</if>
		                    	</volist>
					           		
				            </select>
						</li>
						<li class="shipping" orderid="0">
							<strong>支付方式</strong>
							<!-- 
							<span id="noSelectPage" value="{$shipping.value}">（普通快递：免运费）</span>
							 -->
		           		
		           			<select class="addform_select" name="payTypeId" data-current="" id="payType">
				           		<if condition="count($payType) gt 1 && !$payTypeHasDefault">
		            				<option value="-1">请选择支付方式</option>
	                			</if>
			                	<volist name="payType" id="payType">
			                		<if condition="($payType.isDefault eq '1')">
			                			<option value="{$payType.value}" selected>{$payType.text}</option>
			                		<else />
			                			<option value="{$payType.value}">{$payType.text}</option>
			                		</if>
			                	</volist>
							           		
				            </select>
						</li>
							
						<li class="message" style="display:block;">
							<textarea tag="message" id="message_0" placeholder="给卖家留言"></textarea>
						</li>
						
					</ul>
				</dd>
			</dl>
			</if>
			</volist>
		
		</div>
	
		<div class="pay_area" id="pay_area" style="-webkit-transform-origin: 0px 0px; opacity: 1; -webkit-transform: scale(1, 1);">
			<p class="price" >
				<notempty name="product.fixedPrice">
					应付金额：
   					<notempty name="product.discountedPrice">
						<strong>￥
							<b id="totalPrice">
							{$product['discountedPrice']}
							</b>元</strong>
    				<else />
						<strong>￥
							<b id="totalPrice">
							{$product['fixedPrice']}
							</b>元
						</strong>
     				</notempty>
    			</notempty>
           					
     			<notempty name="product.points">&nbsp;&nbsp;
         			<if condition="$product.pointsType eq 'interact'">
	     				应付积分：
						<strong >
							<b id="totalPrice">
							{$product.points}
							</b>积分
						</strong>
						
        			<else />
	     				应付积分：
						<strong >
							<b id="totalPrice">
							{$product.points}
							</b>积分
						</strong>
        			</if>
        		</notempty>
			</p>
			
			<p class="action">
			<!-- 
				<a href="" id="goPay" style="display:none;" class="wechat">微信支付</a>
	 			<if condition="count($payType) gt 1">
            		<option value="-1">请选择支付方式</option>
               	</if>
			 -->
			 
			<a  id="surePayBtn" class="wechat">提交订单</a>
			<a  id="disableSurePayBtn" class="wechat" style="display:none;">订单信息生成中</a>
			 
			</p>
		</div>
	
	</div>

</div>
	<div class="qb_quick_tip qb_none" id="bubble"></div>

<!-- 
以下没用
	
	<div class="goods info_loading" id="loadingImg" style="display:none;">
    	订单信息生成中<i class="loading"></i>
	</div>
 -->
	
	
	<!-- 
	<div class="mod_tips mod_tips_hdfk" id="payTipsFloat" style="display:none;">
	    <div class="mod_tips_hd">
	        是否确认提交订单？
	    </div>
	    <div class="mod_tips_cnt">
	        <p>付款金额：&yen;<span id="tipsPriceTxt"></span></p>
	        <p id="tipsSevOuter"></p>
	    </div>
	    <div class="mod_tips_ft">
	        <a href="javascript:" class="btn_cancle btn_cancle_mini" id="cancelPayBtn">取消</a>
	        <a href="javascript:" class="btn_sure btn_sure_mini" id="surePayBtn">确认</a>
	    </div>
	</div>
	 -->
	
<script type="text/javascript" src="wx_assets/js/zepto.min.js"></script>
<script id="legos:21914" ver="21914:20131231:201403061451" name="PP.wx.buy" src="wx_assets/js/pp.wx.buy.20131231.js?v=20141209" charset="utf-8"></script>
<!-- 
<script id="legos:21914" ver="21914:20131231:201403061451" name="PP.wx.buy" src="wx_assets/js/storedetail/wg.buyOne.201404041542.js" ></script>
 -->
<script id="legos:21948" ver="21948:20140122:20140218130348" name="PP.wg.mobilereport" src="wx_assets/js/pp.wg.mobilereport.20140122.js?t=20140218130348" charset="gbk"></script>
<script type="text/javascript">
  var objMsg = {p:"paipai.com",weixin:1};
  ECC.cloud.report.pv(objMsg);
</script>
<script>window["PP.mobile.ping.time"]=[new Date()]</script>
<script id="legos:21922" ver="21922:20140103:20140106154115" name="PP.mobile.ping" src="wx_assets/js/pp.mobile.ping.20140103.js?t=20140106154115" charset="gbk"></script>

<script>
var hrefParamsArray = GetSessionIdFromHref(window.location.search);
hrefParamsArray["userName"]='{$userName}';
function GetSessionIdFromHref(search){
　　	var args = search.substring(1); 
　　	var retval = new Array(); 
	args = args.split("&"); 
		for(var i = 0; i < args.length; i ++){ 
			str = args[i]; 
			var arg = str.split("="); 
			if(arg.length <= 1) continue; 
			
			if(arg[0] == 'params') {
				var params = decodeURIComponent(arg[1]);
				var obj = eval('(' + params + ')');
				if (obj.rootid != undefined) {
					retval["rootid"] = obj.rootid;
				}
				if (obj.start != undefined) {
					retval["start"] = obj.start;
				}
				if (obj.tplid != undefined) {
					retval["tplid"] = obj.tplid;
				}
				if (obj.ptype != undefined) {
					retval["ptype"] = obj.ptype;
				}
				if (obj.dtype != undefined) {
					retval["dtype"] = obj.dtype;
				}
				retval["id"] = obj.id;
			} else if(arg[0] == 'customerId') {
				retval["customerId"] = arg[1]; 
			}else if(arg[0] == 'userName'){
				retval["userName"] = arg[1]; 
			} else if(arg[0] == 'method') {
				retval["method"] = arg[1];
			}
		} 
		
		if (retval["start"] == undefined) {
			retval["start"] = 0;
		}
		return retval; 
}

var hrefPath = 'call.html?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
var basePath = 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
var rootId = hrefParamsArray["rootid"] == undefined ? '' : ',"rootid":' + hrefParamsArray["rootid"];
//var preOid = hrefParamsArray["oid"];
var tplid = hrefParamsArray["tplid"];
//var id =  hrefParamsArray["id"] == undefined ? '' : hrefParamsArray["id"];
var id =  '{$id}' == undefined ? '' : '{$id}';

function onAddress(ctrl) {
	var payType = $("#payType").val();
	//订单id
	var id= '{$id}';
	var rootid = '';
	if (hrefParamsArray["rootid"] !== undefined) {
		rootid = ',"rootid":' + hrefParamsArray["rootid"];
	}
	var ptype = '';
	if (payType != -1) {
		ptype = ',"ptype":"' + payType + '"';
	}
	var dtype = '';
   	var a = $("#sendType")[0];
    var curMtype = a.options[a.selectedIndex].getAttribute("mtype");
	if (curMtype != -1) {
		dtype = ',"dtype":"' + curMtype + '"';
	}
	
	//暂时不调用微信共享接口
	if(payType == 'wxpay'){
	  	var baseUrl =  '{$Think.config.SERVER_HOST}';
	 	var urlString = baseUrl + 'call.json?customerId='+ hrefParamsArray["customerId"]+'&userName='+hrefParamsArray["userName"];
	 	$.ajax({url : urlString,
	 		dataType : "json",
	 		type : "post",
	 		timeout: 15000,
	 		data : {
	 			'module': 'product',
	 	        'method' : 'getAddrSign',
	 	        'params' : '{"url":"' + encodeURIComponent(document.location.href) + '"}'
	 	    	},
	 		success : function(data) {
	 			//console.log(data);
	 			//console.log(typeof(data.code));
	 			if (typeof(data.code) == 'undefined' ) {
	 				try{
	 					WeixinJSBridge.invoke('editAddress', {
	 						"appId": data.appId,
	 						"scope" : data.scope,
	 						"signType": data.signType,
	 						"addrSign": data.addrSign,
	 						"timeStamp": data.timeStamp,
	 						"nonceStr": data.nonceStr
	 					},function(res){
	 						if(res.err_msg != 'edit_address:ok'){
	 							if (res.err_msg == 'edit_address:fail') {
	 								return;
	 							} else {
	 							//	alert(res.err_msg);
		 							// 微信中编辑地址失败则使用
		 							var param = window.id == '' ? '' : ',"oid":' + parseInt(window.id);
		 				        	location.href =  window.hrefPath + '&module=product&method=getAddr&params={"tplid":1'
		 				        	+ param +  window.rootId + ptype + dtype +'}';
		 				        	return;
	 							}
	 						}
	 						
	 						window.fullName = res.userName;
	 			        	window.phone = res.telNumber;
	 			        	var addr = res.addressCitySecondStageName + res.proviceFirstStageName + res.addressDetailInfo;
	 			        	window.address = addr;
	 			        	
	 			        	$("#addr_fullName").html(res.userName);
	 			        	$("#addr_phone").html(res.telNumber);
	 			        	$("#addr_detail").html(addr);
		 				});
	 				}
	 				catch(e){
	 					alert("操作失败，请确保在微信浏览器中操作");
	 					return false;
	 				}
	 			}else{
	 				alert(data.msg);
	 				return false;
	 			}
	 			//window.location.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
	 			//+ hrefParamsArray['customerId'] + '&module=product&method=getOrderDetail&params={"tplid":'+hrefParamsArray['tplid']+',"id":' + data.id + rootid + '}';
	 		},
	 		 error: function(jqXHR, textStatus, errorThrown){
	 			 alert('发送超时,可能存在网络异常,检查后请重试...');
	 			 return false;
	 				//$("#showcard").val("保 存");
	 				//$("#showcard").attr("disabled", false);
	 	     }
		});
	} else {
		ctrl.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
		+ hrefParamsArray['customerId'] + '&module=product&method=getAddr&params={"tplid":2,"oid":' + id + rootid + ptype + dtype + '}';
	}
}

function onDetail(ctrl,id) {
	var rootid = '';
	if (hrefParamsArray["rootid"] !== undefined) {
		rootid = ',"rootid":' + hrefParamsArray["rootid"];
	}
	ctrl.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
	+ hrefParamsArray['customerId'] + '&module=product&method=getProduct&params={"allowOrder":0,"tplid":2,"id":"' + id + rootid + '"}';
}

function onStore(ctrl) {
	
	//var id= hrefParamsArray["id"];
	//订单id
	var id= '{$id}';
	var rootid = '';
	if (hrefParamsArray["rootid"] !== undefined) {
		rootid = ',"rootid":' + hrefParamsArray["rootid"];
	}

	var param = id == '' ? '' : ',"oid":' + id;
	
	var ptype = '';
	var payType = $("#payType").val();
	if (payType != -1) {
		ptype = ',"ptype":"' + payType + '"';
	}
	var dtype = '';
   	var a = $("#sendType")[0];
    var curMtype = a.options[a.selectedIndex].getAttribute("mtype");
	if (curMtype != -1) {
		dtype = ',"dtype":"' + curMtype + '"';
	}
	
	ctrl.href = 'call.html?userName=' + hrefParamsArray['userName'] + '&customerId='
	+ hrefParamsArray['customerId'] + '&module=product&method=getPickupStore&params={"tplid":2' + param + rootid + ptype + dtype +'}';

}
</script>

<script type="text/javascript">
    var fullName = '{$fullName}';
    var phone = '{$phone}';
    var address = '{$address}';
    var sid = '{$lastBuyStoreId}';
   // var sid = {$lastBuyStoreId};
    var type, totalPrice;
    
    if (hrefParamsArray["ptype"] !== undefined) {
    	$('#payType').val(hrefParamsArray["ptype"]);
    }
    if (hrefParamsArray["dtype"] !== undefined) {
    	var dcount = $("#sendType")[0].options.length;
    	for (var i = 0; i < dcount; i++) {
    		if ($("#sendType")[0].options[i].getAttribute('mtype') == hrefParamsArray["dtype"]) {
    			$("#sendType")[0].options[i].selected = true;         
    			break; 
    		}
    	}
    }
    
   	if ('{$price}' !== '' && ('{$points}' == '' || '{$points}' == '0')) {
   		type = 'buy';
   		totalPrice =  parseFloat('{$price}') * 100;
   	} else {
   		type = 'point';
   		totalPrice = parseFloat('{$points}');
   	}
   	PP.wx.buy.init();
</script>


<script type="text/javascript">
$(function(){
	var imageUrl = '{$productList[0].picUrl}';
	var title = '{$productList[0].name}';
	var des = '点击这里查看商品';
	var pid =  '{$productList[0].id}';
	var shareUrlString = '{$Think.config.SERVER_HOST}' +  'call.html?customerId='+ hrefParamsArray["customerId"]+'&userName='+
			'&module=product&method=getProduct&params=%7B%22tplid%22:2,%22id%22:' + pid  + '%7D';

	window.shareData = {
		"imgUrl": imageUrl,
		"timeLineLink":  shareUrlString ,
		"sendFriendLink":  shareUrlString ,
		"weiboLink":  shareUrlString ,
		"tTitle": title,
		"tContent": des,
		"fTitle": title,
		"fContent": des,
		"wContent": des
	};
	document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
		// 发送给好友
		WeixinJSBridge.on('menu:share:appmessage', function (argv) {
			WeixinJSBridge.invoke('sendAppMessage', {
				"img_url":  window.shareData.imgUrl,
				"img_width": "640",
				"img_height": "640",
				"link": window.shareData.sendFriendLink,
				"desc": window.shareData.fContent,
				"title": window.shareData.fTitle
			}, function (res) {
				_report('send_msg', res.err_msg);
			})
		});
	
		// 分享到朋友圈
		WeixinJSBridge.on('menu:share:timeline', function (argv) {
			WeixinJSBridge.invoke('shareTimeline', {
				"img_url": window.shareData.imgUrl,
				"img_width": "640",
				"img_height": "640",
				"link": window.shareData.timeLineLink,
				"desc": window.shareData.tContent,
				"title": window.shareData.tTitle
			}, function (res) {
				_report('timeline', res.err_msg);
			});
		});
	
		// 分享到微博
		WeixinJSBridge.on('menu:share:weibo', function (argv) {
			WeixinJSBridge.invoke('shareWeibo', {
				"content": window.shareData.wContent,
				"url": window.shareData.weiboLink
			}, function (res) {
				_report('weibo', res.err_msg);
			});
		});
	});
});
</script>

</body>
</html>